package GUI;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;

import org.jdesktop.application.Application;

import javax.swing.SwingUtilities;


import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import java.sql.Statement; 
import java.util.*;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class MainPage extends javax.swing.JFrame {
	private int location1 = 0;
	private int location2 = 0;

	private JPanel zero;
	private JPanel text;

	private static JLabel SexAge;
	private JPanel title;
	private JPanel jPanel3;
	private JPanel jPanel1;
	private JLabel jLabel1;
	private static JButton SearchButton;
	private static JButton MyMenuButton;
	private static JButton RMButton;
	private JPanel jPanel2;
	private JButton UCButton;
	private JButton R4Button;
	private JButton R3Button;
	private JButton R2Button;
	private JButton GButton;
	private JPanel heading;

	public String Age;
	private JButton LG1Button;
	private JButton R1Button;
	private JButton FirstButton;
	private JButton OthersButton;
	private JButton LG7Button;
	private JButton LG5Button;
	public String Sex;
	public void valuePass(String sex, String age)
	{
		Sex = sex;
		Age = age;		
		SexAge.setText(Sex + "  " + Age);
	}
	
	public String LocationLG1 = "select * from mydb.food where offerby = 'LG1'";
	public String LocationLG = "select * from mydb.food where offerby = 'LG'";
	public String LocationLG5 = "select * from mydb.food where offerby = 'LG5'";
	public String LocationLG7 = "select * from mydb.food where offerby = 'LG7'";
	

	/**
	* Auto-generated main method to display this JFrame
	*/
	public void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				MainPage inst = new MainPage();	
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public MainPage() {
		super();
		initGUI();
	}
	
	

    
	class ActionRestaurantMenu implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			}}
	 class Action2 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			myMenu frame = new myMenu();
			frame.setVisible(true);
			dispose();
			}}
	 class Action3 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			search frame = new search();
			frame.setVisible(true);
			dispose();
			}}

	 
	 class ActionLG implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG = "select * from mydb.food where offerBy = 'Coffee Shop'" ;
			RM inst = new RM();
			inst.location(LG,true);
			dispose();
			}}
	 

	
	 
	 class ActionHalal implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'Halal Food Counter'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 //ActionMcDonald
	 
	 class ActionMcDonald implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'McDonald'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 class ActionAsia implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'Asia Pacific Caterin'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 //Gold Rice Bowl Delicious Food
	 
	 class ActionGold implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'Gold Rice Bowl Delicious Food'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 //Milano Fresh
	 class ActionMilano implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'Milano Fresh'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 class ActionUni implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'Uni-Bar'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 class ActionUC implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'U C Bistro'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 class ActionSea implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			String LG7 = "select * from mydb.food where offerBy = 'Seafront Cafeteria'" ;
			RM inst = new RM();
			inst.location(LG7,true);
			dispose();
			}} 
	 
	 class ActionG implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location1 = 1;
			R1Button.setVisible(true);
			R2Button.setVisible(false);
			R3Button.setVisible(false);
			R4Button.setVisible(false);
			R1Button.setText("Chinese Restaurant");
		}} 	 
	 
	 class ActionLG1 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location1 = 2;
			R1Button.setVisible(true);
			R2Button.setVisible(false);
			R3Button.setVisible(false);
			R4Button.setVisible(false);
			R1Button.setText("Canteen II");
		}} 	
	 
	 class ActionLG5 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location1 = 3;
			R1Button.setVisible(true);
			R2Button.setVisible(false);
			R3Button.setVisible(false);
			R4Button.setVisible(false);
			R1Button.setText("McDonald");
		}} 	
	 
	 class ActionLG7 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location1 = 4;
			R1Button.setVisible(true);
			R2Button.setVisible(true);
			R3Button.setVisible(true);
			R4Button.setVisible(false);
			R1Button.setText("Milano Fresh");
			R2Button.setText("Gold Rice Bowl Delicious Food");
			R3Button.setText("Asia Pacific Caterin ");
		}} 
	 
	 class ActionFirst implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location1 = 5;
			R1Button.setVisible(true);
			R2Button.setVisible(true);
			R3Button.setVisible(false);
			R4Button.setVisible(false);
			R1Button.setText("Coffee Shop");
			R2Button.setText("Halal Food Counter");
		}} 

	 class ActionOthers implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location1 = 6;
			R1Button.setVisible(true);
			R2Button.setVisible(true);
			R3Button.setVisible(true);
			R4Button.setVisible(true);
			R1Button.setText("LSK Business Building Restaurant");
			R2Button.setText("Uni-Bar");
			R3Button.setText("U C Bistro ");
			R4Button.setText("Seafront Cafeteria");
		}} 
	 
	 class ActionR1 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location2 = 1;
			String LG1="";
			if(location1==1 )
			{
				LG1 = "select * from food where offerby = 'Chinese Restaurant'" ;
			}
			if(location1==2)
			{
				LG1 = "select * from food where offerby = 'Canteen II'" ;
			}
			if(location1==3)
			{
				LG1 = "select * from food where offerby = 'McDonald'" ;
			}
			if(location1==4)
			{
				LG1 = "select * from food where offerby = 'Milano Fresh'" ;
			}
			if(location1==5)
			{
				LG1 = "select * from food where offerby = 'Coffee Shop'" ;
			}
			if(location1==6)
			{
				LG1 = "select * from food where offerby = 'LSK Business Building Restaurant'" ;
			}
			RM inst = new RM();
			inst.location(LG1,true);
			dispose();
		}} 
	
	 class ActionR2 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location2 = 1;
			String LG1="";
			if(location1==4)
			{
				LG1 = "select * from food where offerby = 'Gold Rice Bowl Delicious Food'" ;
			}
			if(location1==5)
			{
				LG1 = "select * from food where offerby = 'Halal Food Counter'" ;
			}
			if(location1==6)
			{
				LG1 = "select * from food where offerby = 'Uni-Bar'" ;
			}
			RM inst = new RM();
			inst.location(LG1,true);
			dispose();
		}} 
	 
	 class ActionR3 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location2 = 1;
			String LG1="";
			if(location1==4)
			{
				LG1 = "select * from food where offerby = 'Asia Pacific Caterin '" ;
			}

			if(location1==6)
			{
				LG1 = "select * from food where offerby = 'U C Bistro'" ;
			}
			RM inst = new RM();
			inst.location(LG1,true);
			dispose();
		}} 
	 
	 class ActionR4 implements ActionListener{    
		public void actionPerformed(ActionEvent e){
			location2 = 1;
			String LG1="";


			if(location1==6)
			{
				LG1 = "select * from food where offerby = 'Seafront Cafeteria'" ;
			}
			RM inst = new RM();
			inst.location(LG1,true);
			dispose();
		}} 
	 
	 
	private void initGUI() {
		try {
			GridBagLayout thisLayout = new GridBagLayout();
			thisLayout.rowWeights = new double[] {0.0, 0.1};
			thisLayout.rowHeights = new int[] {54, 7};
			thisLayout.columnWeights = new double[] {0.0, 0.1};
			thisLayout.columnWidths = new int[] {113, 7};
			getContentPane().setLayout(thisLayout);
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				zero = new JPanel();
				getContentPane().add(zero, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
			}
			{
				heading = new JPanel();
				getContentPane().add(heading, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				heading.setName("heading");
				{
					jLabel1 = new JLabel();
					heading.add(jLabel1);
					jLabel1.setName("jLabel1");
					jLabel1.setText("HKUST Food Advisor");
					jLabel1.setPreferredSize(new java.awt.Dimension(398, 47));
				}
			}
			{
				jPanel2 = new JPanel();
				GridBagLayout jPanel2Layout = new GridBagLayout();
				jPanel2Layout.rowWeights = new double[] {0.0, 0.0, 0.0, 0.0};
				jPanel2Layout.rowHeights = new int[] {40, 40, 40, 40};
				jPanel2Layout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
				jPanel2Layout.columnWidths = new int[] { 7};
				jPanel2.setLayout(jPanel2Layout);
				getContentPane().add(jPanel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				jPanel2.setName("jPanel2");
				{
					RMButton = new JButton();
					jPanel2.add(RMButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					RMButton.setName("jButton5");
					RMButton.addActionListener(new ActionRestaurantMenu());   
					RMButton.setText("Restaurant Menu");
				}
				{
					SearchButton = new JButton();
					jPanel2.add(SearchButton, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					SearchButton.setName("jButton7");
					SearchButton.setLocale(new java.util.Locale("da"));
					SearchButton.addActionListener(new Action3());   
					SearchButton.setText("Search");
				}
				{
					MyMenuButton = new JButton();
					jPanel2.add(MyMenuButton, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					MyMenuButton.setName("jButton6");
					MyMenuButton.addActionListener(new Action2()); 
					MyMenuButton.setText("My Menu");
				}
			}
			{
				jPanel1 = new JPanel();
				getContentPane().add(jPanel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				jPanel1.setName("jPanel1");
				{
					JButton jButton4 = new JButton();
					zero.add(jButton4);
					jButton4.setName("jButton4");
					jButton4.setPreferredSize(new java.awt.Dimension(110, 50));
					try {
					    Image img = ImageIO.read(getClass().getResource("2.jpg"));
					    jButton4.setIcon(new ImageIcon(img));
					  } catch (IOException ex) {
						  
					  }
				}
				
			}
			{
				jPanel3 = new JPanel();
				GridBagLayout jPanel3Layout = new GridBagLayout();
				getContentPane().add(jPanel3, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
				jPanel3.setName("jPanel3");
				jPanel3Layout.rowWeights = new double[] {0.0, 0.1, 0.1, 0.1};
				jPanel3Layout.rowHeights = new int[] {32, 7};
				jPanel3Layout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
				jPanel3Layout.columnWidths = new int[] { 7};
				jPanel3.setLayout(jPanel3Layout);
				{
					title = new JPanel();
					jPanel3.add(title, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					title.setName("title");
					{
						SexAge = new JLabel();
						title.add(SexAge);
						SexAge.setName("jLabel2");
						SexAge.setPreferredSize(new java.awt.Dimension(224, 29));
					}

				}
				{
					text = new JPanel();
					GridBagLayout textLayout = new GridBagLayout();
					jPanel3.add(text, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
					text.setName("text");
					textLayout.rowWeights = new double[] {0.1, 0.1, 0.1, 0.1};
					textLayout.rowHeights = new int[] {7, 7, 7, 7};
					textLayout.columnWeights = new double[] {0.1, 0.1, 0.1, 0.1};
					textLayout.columnWidths = new int[] {7, 7, 7, 7};
					text.setLayout(textLayout);
					{
						UCButton = new JButton();
						text.add(UCButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
						UCButton.setName("UCButton");
						UCButton.setPreferredSize(new java.awt.Dimension(332, 34));
						UCButton.setText("U C Bistro");
						UCButton.addActionListener(new ActionUC());
						UCButton.setVisible(false);
					}
					{
						GButton = new JButton();
						text.add(GButton, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						GButton.setName("GButton");
						GButton.setText("      G/F      ");
						GButton.addActionListener(new ActionG());
						
					}
					{
						LG1Button = new JButton();
						text.add(LG1Button, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						LG1Button.setName("LG1Button");
						LG1Button.setText("     LG1     ");
						LG1Button.addActionListener(new ActionLG1());
					}
					{
						LG5Button = new JButton();
						text.add(LG5Button, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						LG5Button.setName("LG5Button");
						LG5Button.setText("    LG5    ");
						LG5Button.addActionListener(new ActionLG5());
					}
					{
						LG7Button = new JButton();
						text.add(LG7Button, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						LG7Button.setName("LG7Button");
						LG7Button.setText("      LG7      ");
						LG7Button.addActionListener(new ActionLG7());
					}
					{
						OthersButton = new JButton();
						text.add(OthersButton, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						OthersButton.setName("OthersButton");
						OthersButton.setText("   Others   ");
						OthersButton.addActionListener(new ActionOthers());
					}
					{
						FirstButton = new JButton();
						text.add(FirstButton, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
						FirstButton.setName("FirstButton");
						FirstButton.setText("Lift17/18-25/26");
						FirstButton.addActionListener(new ActionFirst());
					}
					{
						R1Button = new JButton();
						text.add(R1Button, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
						R1Button.setName("R1Button");
						R1Button.setText("R1");
						R1Button.setVisible(false);
						R1Button.addActionListener(new ActionR1());
					}
					{
						R2Button = new JButton();
						text.add(R2Button, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
						R2Button.setName("R2Button");
						R2Button.setText("R2");
						R2Button.setVisible(false);
						R2Button.addActionListener(new ActionR2());
					}
					{
						R3Button = new JButton();
						text.add(R3Button, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTH, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
						R3Button.setName("R3Button");
						R3Button.setText("R3");
						R3Button.setVisible(false);
						R3Button.addActionListener(new ActionR3());
					}
					{
						R4Button = new JButton();
						text.add(R4Button, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, new Insets(15, 0, 0, 0), 0, 0));
						R4Button.setName("R4Button");
						R4Button.setText("R4");
						R4Button.setVisible(false);
						R4Button.addActionListener(new ActionR4());
					}

				}

			}

			pack();
			this.setSize(650, 600);
			Application.getInstance().getContext().getResourceMap(getClass()).injectComponents(getContentPane());
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

	private void setfoodVisible() {
		// TODO Auto-generated method stub
		
	}

}
